package com.xcjh.base;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.support.SFunction;
import com.baomidou.mybatisplus.extension.conditions.query.LambdaQueryChainWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import java.util.List;

public class XcjhBaseService<M extends BaseMapper<T>, T> extends ServiceImpl<M, T> {

    protected LambdaQueryChainWrapper<T> find() {
        return new LambdaQueryChainWrapper<>(getBaseMapper());
    }

    protected LambdaQueryWrapper<T> wrapper() {
        return new LambdaQueryWrapper<T>();
    }

    protected T findBy(LambdaQueryWrapper<T> wrapper) {
        return getBaseMapper().selectOne(wrapper);
    }

    protected T findBy(SFunction<T, ?> func, Object value) {
        return find().eq(func, value).one();
    }

    protected List<T> findListBy(SFunction<T, ?> func, Object value) {
        return find().eq(func, value).list();
    }

    protected List<T> findListBy(LambdaQueryWrapper<T> wrapper) {
        return getBaseMapper().selectList(wrapper);
    }

    protected <E extends IPage<T>> E findPageBy(SFunction<T, ?> func, Object value, E page) {
        return find().eq(func, value).page(page);
    }

    protected <E extends IPage<T>> E findPageBy(LambdaQueryWrapper<T> wrapper, E page) {
        return getBaseMapper().selectPage(page,wrapper);
    }

}
